package com.fenqing.leetcode.code.t200_300;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fenqing
 */
public class Topic219 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入1
     * @param input2 输入2
     */
    public Topic219(String input1, String input2) {
        super(input1, input2);
    }

    @Execute
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            Integer index = hash.get(num);
            if (index != null && i - index <= k) {
                return true;
            }
            hash.put(num, i);
        }
        return false;
    }

    public static void main(String[] args) {
        Topic219 topic219 = new Topic219(
                """
               [99,99]
                """,
                "2"
        );
        boolean run = topic219.run();
        System.out.println(run);
    }

}
